using System;
using OracleInternal.Json.Binary;
using OracleInternal.Json.Common;

namespace OracleInternal.Json.Sql
{
	internal class OracleJsonIntervalDS : OracleJsonValue
	{
		internal const int INTERVALDS_LEN = 11;

		private byte[] m_raw;

		internal OracleJsonIntervalDS(byte[] raw)
		{
			m_raw = raw;
		}

		internal OracleJsonIntervalDS(TimeSpan d)
		{
			m_raw = OsonPrimitiveConversions.DurationToIntervalDS(d);
		}

		public override OracleJsonType GetOracleJsonType()
		{
			return OracleJsonType.INTERVALDS;
		}

		public override string ToJsonString()
		{
			return OracleJsonSerializer.SerializeString(GetJsonString());
		}

		internal string GetJsonString()
		{
			return OsonPrimitiveConversions.SerializeIntervalDS(OracleJsonExceptions.ORACLE_FACTORY, Raw());
		}

		internal byte[] Raw()
		{
			return m_raw;
		}

		internal TimeSpan GetDuration()
		{
			return OsonPrimitiveConversions.IntervalDSToDuration(Raw());
		}

		internal static string SerializeDuration(TimeSpan d, IExceptionFactory f)
		{
			byte[] raw = OsonPrimitiveConversions.DurationToIntervalDS(d);
			return OsonPrimitiveConversions.SerializeIntervalDS(f, raw);
		}

		internal OracleJsonIntervalDS GetINTERVALDS()
		{
			return this;
		}
	}
}
